<?php
namespace app\index\controller;

class Login extends Base{
	public function index(){
		if(session('?username')){
			$this->redirect('Member/index');
		}
		$cat = $this->category();
        $catname = '登录';
        $seo = $this->site();
        $seo['site_title'] = $catname.' - '.$seo['site_title'];
    	$this->assign('seo', $seo);
		return $this->fetch();
	}
	public function checkLogin(){
		//status 1 登录成功 2 账户密码错误 3 账户锁定
		$username = isset($_REQUEST['username']) ? input('param.username') : exit('2');
		$password = isset($_REQUEST['password']) ? input('param.password') : exit('2');
		$r = db('member')->where('username', $username)->find();
		$password = md5(md5(trim($password)).$r['encrypt']);
		if(!$r){
			exit('2');
		}elseif($r['password'] != $password){
			exit('2');
		}elseif($r['islock']){
			exit('3');
		}else{
			db('member')->where('username', $r['username'])->update(['lastdate' => time()]);
			session('userid', $r['userid']);
			session('username', $r['username']);
			exit('1');
		}
	}
	public function logout(){
		session('userid', null);
		session('username', null);
		$this->redirect('Login/index');
	}
}